﻿using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

public class MapInit : MonoBehaviour
{
    const float mapOffsetX = 44.7f;

    const float mapOffsetY = 36f;

    public Vector2 originPos = new Vector2(0, 0);

    static public List<GameObject> hexCells = new List<GameObject>();

    static public bool isGenerated;
    [SerializeField]
    private GameObject hex;

    public int randomSizeX=0;   //指定要生成地图的大小

    public int randomSizeY=0;

    private void Start()
    {
        if(randomSizeX==0)
        randomSizeX = Random.Range(3, 10);
        if(randomSizeY==0)
        randomSizeY = Random.Range(3, 5);
        randomSizeX = 5;
        randomSizeY = 6;
        isGenerated = false;
        GenerateBasicMap();
    }
     
    public void GenerateBasicMap()//按照固定方式生成主要地图
    {
        if (isGenerated) { Debug.LogError("Is Gen!"); return; }

        for (float i = 0; i < randomSizeX; i++)
        {
            for (float j = 0; j < randomSizeY; j++)
            {
				if(j % 2 == 1)
				Instantiate(hex, new Vector2(i * mapOffsetX + 22.1f, j * mapOffsetY), Quaternion.identity);
                else
				Instantiate(hex, new Vector2(i * mapOffsetX, j * mapOffsetY), Quaternion.identity);
            }
        }
        isGenerated = true;
    }
        //public void GenerateRandomMap()
        //{
        //    for (int i = 0; i < randomSizeX; i++)
        //    {
        //        for (int j = 0; j < randomSizeY; j++)
        //        {
        //            HexCells newHex = new HexCells(i, j);
        //            hexCells.Add(newHex);
        //        }
        //    }

        //    for(int i = 0;i < randomSizeX-1;i++)
        //    {
        //        for(int j = 0; j <randomSizeY-1;j++)
        //        {

        //        }
        //    }

        //    foreach (HexCells _hexcell in hexCells)
        //    {
        //        _hexcell.ChangeStatusRandomly();
        //    }
        //}
    
}
